\documentclass[letter]{article}

% Welcome to the Latex torture test file.  Please add your ugliest latex syntax examples 
% to the appropriate place in this file so we can make sure that Latex works consistently 
% for all of us.

% To make this document more colorful you may want to turn on other:Latex Theme

%preamble type stuff here

% The following line is to make sure that backticks in catcode are caught properly
\catcode`\{=2
\catcode`\(=2
\catcode`\"=2

% The following four lines should be all math:
$\sin(x)$
$$\sin(x)$$
\[\sin(x)\]
\(\sin(x)\)

``$\sin(x)$\textit{italic}'' % Math etc in strings!!
` single quotes should not be paired as strings, as they appear alone too often.'
% Math environments
\begin{equation}
  \sin(x)
\end{equation}

\begin{align*}
  \sin(x)
\end{align*}

% 6/14/05  many of the commands below are functions with arguments.  When recursion is in place these should work nicely.

\foo[f]{bar}{$10 + 20$} Here is a simple single function with several parameters

% Catch commands followed by space properly so that this is not a mess:
\foo{\bar [}
\foo{\bar {stuff}}
\foo{{\sf stuff}}
\foo{{stuff}}
% Maybe at some point deal with this. 4 is supposed to be the argument for \foo.
\foo4


LaTeX commands start with a \\ which must be followed by a single non-letter character, or one-or more letter characters.  LaTeX commands do not have numbers or underscores or any other non-letter character in them  so \this-is-not-a-legal-command.

\newcommand{\uint}{\mathop{\mathchoice%
{\rlap{\smash{$\displaystyle\intop\limits^{\uintbar}$}}}%
{\rlap{\smash{$\textstyle\intop\limits^{\uintbar}$}}}%
{\rlap{\smash{$\scriptstyle\intop\limits^{\uintbar}$}}}%
{\rlap{\smash{$\scriptscriptstyle\intop\limits^{\uintbar}$}}}%
}\!\int}

\smash{$foobar$}

This is a dollar sign \$ in the tex code, it should not start math mode.
This is a dollar sign$\$$ in math code, it should not stop math mode.

Except that $$\int_{C_{t}}e^{g(z,t)}f(z,t)\d z$$ where $g,f$ is apparently something called displaymath mode.

This sentence contains some \verb!verbatim statements! in it.  It is also legal to have a sentence with \verb*|verbatim stuff|.  The * tells latex to make the spaces visible as squashed u characters like this \verb*~ ~.  Strangely the documentation says that \verbbthis should workb but  is getting matched by keyword.tex.general unless the b is followed by  a space (not too likely) However in that case using letter as a delimiter is silly, just use a number \verb3which works fine 3.  \verb!constructs will also stop matching at the end of a line, even though it will cause a latex error.

This is a non-math Latex Symbol \textdiv it should be scoped as constant.character.latex
$D_1=\{x_1^2\}  \foo{bar}$

% Main document stuff here.
\begin{document}

\maketitle
\chapter{Chapter One}

\input{Chapter1.tex}

%itemize environment
\begin{itemize}
    \item Item one
    \item Item $2$
    \item item three with \textbf{bold text}
\end{itemize}

\section{Second one}
%enumerate environment
\begin{enumerate}
    \item Item one
    \item Item $2$
    \item item three with \textit{italic text}
\end{enumerate}

% emph, textit, textbf etc
\textit{Italic text with math in it: $e^{frac{1}{2}}$. Also, an itemize list:
\begin{itemize}
  \item Item one, inside textit.
\end{itemize}
\textbf{And some bold face}.
}

\textbf{Some bold face by itself.}
\emph{Emphasized text. Possibly rendered as italic?}

% Footnotes, citations, references
\footnote{A footnote. Math in the footnote: $\frac{1}{2}$. \textbf{Bold face in the footnote}.}
\cite{citekey}
\citealt{citekey}
\citep{citekey:withsemicolon} % This should be all matched as one citekey
\citeauthor{1985Metic..20..367D}  % This should be all matched as one citekey
\footcite{citekey,secondkey}
\footcitetitle{citekey}
\ref{Reference Label}

% the listing environment 
\begin{lstlisting}[caption=The Vertex Class,label=lst:vertex,float=htbp]
class Vertex:
    def __init__(self,num):
        self.id = num
        self.adj = []
        self.color = 'white'
        self.dist = sys.maxint
        self.pred = None
        self.disc = 0
        self.fin = 0
        self.cost = {}

    def addNeighbor(self,nbr,cost=0):
        self.adj.append(nbr)
        self.cost[nbr] = cost
\end{lstlisting}

\subsection{Subsection one}\label{sec:testLabel}
This is a paragraph with some math $ \sin{3.1415} * \cos{3.1415} \angle  $.  This is an ordinary sentence after the math.  This works just fine with math mode including a rule for a bunch of math symbols.

\section[Optional title]{section 1}

\subsubsection{SubSubsection one point one}
%description environment
\begin{description}
    \item[Item one]  and some more.
    \item[Item $2$] and $2+2 = 4$
    \item[Item three] with \texttt{typewrsdfiter text}
\end{description}

\paragraph{Paragraph One}

\begin{inparaenum}
  \item increase impurity concentration or $L_{z}$ (impurity species);
  \item increase the recycling neutral concentration to increase $\Delta
    Q_{\text{at}}$ and $\Delta M_{\text{at}}$; 
  \item reduce the power flux
    ($P_{\text{sep}} / A_{\text{sep}})$ transported across the separatrix
    (e.g.  by increased radiation inside the separatrix, by reduced auxiliary
    heating or by increased plasma surface area); and \item increase the
    connection length $L_{\text{\abbr{SOL}}} = q_{95}\pi R$.
\end{inparaenum}
it can be shown from~(\ref{eq14-26}) that $\Delta M_{\text{at}} \sim$

\section{String Test Cases}

`foo' This is a correct `single quoted string.'  This is a correct ``double quoted string.''
This is an invalid "string".  This is also 'invalid.'  but a word with an apostrophe isn't highlighted. 'ever.'  What if we escape the \"and make it look like a quote\"  or even \' another possible \'  We should also be able to escape a \` (backtick) so they don't fake out the quote rules.
'foo' is also bad.
"foo" is too.

Here is a fun example where a multi argument tex function can contain a latex environment!  to get the nested begin ends colored correctly we could include text.tex.latex instead of text.tex in the meta.function.with-arg.tex rule.  Not sure thats a good idea though....
\begin{figure}[htbp]
  \centering
  \subfigure[]{
    \label{fig:dija}
    \begin{minipage}[b]{0.32\textwidth}
        \centering \includegraphics[width=5.2cm]{Graphs/dijkstraa}
      \end{minipage}}%%
  \subfigure[]{
    \label{fig:dijb}
    \begin{minipage}[b]{0.32\textwidth}
        \centering \includegraphics[width=5.2cm]{Graphs/dijkstrab}
      \end{minipage}}%%
  \label{fig:dijstep}
  \caption{Tracing Dijkstra's Algorithm}
\end{figure}


\begin{split}
  \Delta_n &=\frac{D_\bot }{\left( {{\Gamma_\bot } / {n_{\text{\abbr{SOL}}} }} \right)}\\
  \Delta_T &=\frac{\chi_\bot }{\left( {{Q_\bot } / {n_{\text{\abbr{SOL}}}
          T_{\text{\abbr{SOL}}} }} \right)-3{D_\bot } / {\Delta_n }}
\end{split}

% Make sure that the begin end patterns for section don't always match the first }
% Do section commands ever span more than one line????  I'm guessing not in 99% of the cases.
\section{$\mathcal{D}$-modules}

% part is tricky because it is used in the exam style and is also used in reports.
\part[4] $\sqrt[d]{n!}$  Hmmm, It would be nice to color math functions somehow....
$\bigcup$

\foobar some ordinary text

\begin{verbatim}
	This is some verbatim text.
\end{verbatim}

\end{document}